{% extends "base.html" %}
{% block content %}
<h1>Simple(st) Form View</h1>
<p>Simply declare a few parameters as
<ul>
<li><code>template_name</code> for template to use (as you did with Views)</li>
<li><code>form_class</code> for Form object (default is standard django Form object)</li>
<li><code>process_form</code> method to deal with cleaned data</li>
<li>Another View for success</li>
</ul>
<p>Form used in all three examples</p>
<div class="highlight"><pre>
<span class="k">class</span> <span class="nc">TestForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">Form</span><span class="p">):</span>
    <span class="n">username</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">30</span><span class="p">)</span>
    <span class="n">password</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">30</span><span class="p">,</span> <span class="n">widget</span><span class="o">=</span><span class="n">forms</span><span class="o">.</span><span class="n">PasswordInput</span><span class="p">)</span>

    <span class="nd">@property</span> <span class="c"># 0.96 compatible</span>
    <span class="k">def</span> <span class="nf">cleaned_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">clean_data</span>
</pre></div>

<p>The form, eventually:</p>
<form action="" method="POST">
{{ form }}
<input type="submit">
</form>

<div class="highlight"><pre>
<span class="kn">from</span> <span class="nn">obviews.views</span> <span class="kn">import</span> <span class="n">View</span><span class="p">,</span> <span class="n">FormView</span><span class="p">

<span class="c"># simplest form</span>
<span class="k">class</span> <span class="nc">SucessView</span><span class="p">(</span><span class="n">View</span><span class="p">):</span>
    <span class="n">template_name</span> <span class="o">=</span> <span class="s">&quot;forms/success.html&quot;</span>
    
<span class="k">class</span> <span class="nc">SimplestForm</span><span class="p">(</span><span class="n">FormView</span><span class="p">):</span>
    <span class="n">template_name</span> <span class="o">=</span> <span class="s">&quot;forms/simplest_form.html&quot;</span>
    <span class="n">defaults</span> <span class="o">=</span> <span class="p">{</span><span class="s">&quot;on_success&quot;</span><span class="p">:</span> <span class="s">&quot;/form/success/&quot;</span><span class="p">}</span>
    <span class="n">form_class</span> <span class="o">=</span> <span class="n">TestForm</span>

    <span class="k">def</span> <span class="nf">process_form</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">form</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="o">**</span><span class="n">variables</span><span class="p">):</span>
        <span class="k">pass</span>

<span class="n">urlpatterns</span> <span class="o">+=</span> <span class="n">patterns</span><span class="p">(</span><span class="s">&#39;&#39;</span><span class="p">,</span>                
    <span class="p">(</span><span class="s">&#39;^form/simplest/$&#39;</span><span class="p">,</span> <span class="n">SimplestForm</span><span class="p">()),</span>
    <span class="p">(</span><span class="s">&#39;^form/success/$&#39;</span><span class="p">,</span> <span class="n">SucessView</span><span class="p">()),</span>
 <span class="p">)</span>

</pre></div>
<p>This one was easy (nothing really done here) but watch <strong>next one</strong> for <a href="/form/register/">real processing</a></p>
{% endblock %}
